package ru.st.selenium.pages;

import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfElementLocated;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

public class FilmPage extends InternalPage {

	public FilmPage(PageManager pages) {
		super(pages);
	}
	
  @FindBy(name = "name")
  private WebElement titleField;
	
  @FindBy(name = "year")
  private WebElement yearField;
  
  @FindBy(name = "submit")
  public WebElement submitButton;
  
  public FilmPage setTitleField(String text) {
	    titleField.sendKeys(text);
	    return this;
  }  

  public FilmPage setYearField(String text) {
	    yearField.sendKeys(text);
	    return this;
  }

  public FilmPage clickSubmitButton() {
	    submitButton.click();
		return this;
  }

  public FilmPage ensurePageLoaded() {
	    super.ensurePageLoaded();
	    wait.until(presenceOfElementLocated(By.id("year")));
	    return this;
  }
}